import { ApplicationController } from "../support/application-controller"
import axios from 'axios'

export default class extends ApplicationController {
  initialize () {
    console.log("init...")
  }

  register () {
    console.log("register...");
    var reg_phone = document.getElementById("reg_phone").value;
    var uid = document.getElementById("uid").value;
    if (reg_phone === '') {
      alert('注册电话不能为空.');
    } else {
      axios.post('/api/v1/users/share.json', {
        phone: reg_phone,
        uid: uid
      }).then(function (response) {
        if (response.data.result) {
          document.getElementById("invites-bg").style.display = "none";
          document.getElementById("invites-success").style.display = "block";
        } else {
          alert(response.data.message);
        }
      }).catch(function (error) {
        if (error.response) {
          console.log(error.response.data);
          console.log(error.response.status);
          console.log(error.response.headers);
        }
      });
    }
  }
}